#!/bin/sh -eu
#
# Copyright 2008 Mattias Norrby
#
# This file is part of Test Dept..
#
# Test Dept. is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Test Dept. is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Test Dept..  If not, see <http://www.gnu.org/licenses/>.

TEST_MAIN="$1"
SUT="$2"
DEST="$3"

TMPFILE="/tmp/test_dept_stubs$$"

if echo "# symbols to replace to make stubbable code" >${TMPFILE}; then
  echo "Alles gut" >/dev/null
else
  echo "$0: Could not create ${TMPFILE}" >&2
  exit 2
fi

for symbol in `nm $TEST_MAIN | sed -n '/test_dept.*set/s/.*test_dept_\(.*\)_set$/\1/p'`; do
  echo ${symbol} test_dept_proxy_${symbol} >>${TMPFILE}
done

objcopy --redefine-syms ${TMPFILE} ${SUT} ${DEST}

rm ${TMPFILE}
